Shader "FrameWork/Day18AlphaClip"
{
    properties
    {
        _BaseMap("Base Map",2d) = "white"{}
        _BaseColor("Base Color",color) = (1,1,1,1)
        _AlphaIntensity("Alpha Intensity",Range(0,2)) = 1
        [Toggle(_ALPHATEST_ON)]_AlphaToggle("AlphaToggle",float) = 1
        [Enum(off,0,front,1,back,2)]_Cull("Cull",float) = 1
        
    }
    
    subshader
    {
        Tags
        {
            "RenderPipeline" = "UniversalPipeline"
            "RenderType" = "Opaque"
            "Queue" = "Geometry"
        }
        
        HLSLINCLUDE
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

            CBUFFER_START(UnityPerMaterial)
        
            TEXTURE2D(_BaseMap);SAMPLER(sampler_BaseMap);float4 _BaseMap_ST;
            float4 _BaseColor;
            float _Cull;
            float _AlphaIntensity;
            CBUFFER_END
        ENDHLSL

        pass
        {
            Name "FrameworkDay17"
            Cull[_Cull]
            
            
            Tags
            {
            }
            HLSLPROGRAM
            #pragma vertex UnlitPassVertex
            #pragma fragment UnlitPassFragment
            #pragma shader_feature _ALPHATEST_ON
            
            struct Attributes
            {
                float4 posOS        :POSITION;
                float2 uv           :TEXCOORD0;
                float4 color        :COLOR;
            };

            struct Varyings
            {
                float4 positionCS    :SV_POSITION;
                float2 uv            :TEXCOORD0;
                float4 color         :COLOR;
            };

            Varyings UnlitPassVertex(Attributes IN)
            {
                Varyings OUT = (Varyings)0;
                const VertexPositionInputs position_inputs = GetVertexPositionInputs(IN.posOS.xyz);
                OUT.positionCS = position_inputs.positionCS;
                OUT.uv = TRANSFORM_TEX(IN.uv,_BaseMap);
                OUT.color = IN.color;
                return OUT;
            }

            half4 UnlitPassFragment(Varyings IN) :SV_TARGET
            {

                
                const half4 baseMap = SAMPLE_TEXTURE2D(_BaseMap,sampler_BaseMap,IN.uv);
                #ifdef _ALPHATEST_ON
                /*
                    if(baseMap.a<0.5)
                        discard;
                */
                     clip(baseMap.a - _AlphaIntensity);
                return baseMap;
                #endif
                return baseMap * _BaseColor * IN.color;
            }


            ENDHLSL
        }
    }

    Fallback  "Hidden/Universal Render Pipeline/FallbackError"
}
